<template>
  <div class="dimension-indicator-settings">
    <el-popover
      ref="popover"
      placement="bottom"
      title=""
      width="180"
      trigger="click"
      @show="showColums"
    >
      <div class="setting-title">
        <span>{{ $t('选择展示信息') }}</span>
      </div>
      <el-row
        v-for="item in originalAllColumns"
        :key="item.listColumnName"
        class="right-select"
      >
        <el-col :span="24">
          <div
            style="
              display: flex;
              justify-content: space-between;
              line-height: 30px;
            "
          >
            <el-checkbox
              v-model="item.showFlag"
              :true-label="1"
              :false-label="0"
              :disabled="item.editFlag === 0"
              @change="(arg) => doSelected(arg, item)"
              >{{
                lang == 'zh-CN' ? item.tableColumnName : item.listColumnName
              }}</el-checkbox
            >
          </div>
        </el-col>
      </el-row>
      <el-button slot="reference" icon="el-icon-s-operation"></el-button>
      <div class="bottom-btn">
        <span @click="confirmSave()">{{ $t('确 定') }}</span>
      </div>
    </el-popover>
  </div>
</template>
<script>
import globalService from '@/services/globalService'
import { mapGetters } from 'vuex'
export default {
  components: {},
  props: {
    type: Number,
    apiObj: {
      type: Object,
      default: () => {},
    },
    definitionCode: String,
    templateTypeCode: String,
    projectDetailCode: String,
  },
  computed: {
    ...mapGetters(['lang']),
  },
  data() {
    return {
      dialogVisible: true,
      originalAllColumns: [],
    }
  },
  methods: {
    showColums() {
      this.queryAllColumns()
    },
    queryAllColumns() {
      globalService
        .queryColumnList({
          tableType: this.type,
          definitionCode: this.definitionCode,
          projectDetailCode: this.projectDetailCode,
        })
        .then((res) => {
          this.originalAllColumns = (res.data.data || []).map((it) => {
            return {
              ...it,
              showFlag: Number(it.showFlag),
            }
          })
        })
    },
    doSelected(val, item) {},
    closeDialog() {
      this.dialogVisible = false
      this.$emit('input', false)
    },
    confirmSave() {
      let params = {
        tableType: this.type,
        columsList: JSON.stringify(this.originalAllColumns),
        templateTypeCode: this.templateTypeCode,
      }
      console.log(params, 'ssss')
      globalService.setCustomTableColumns(params).then((res) => {
        this.$message.success(this.$t('设置成功'))
        this.$emit('reload')
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.dimension-indicator-settings-dialog {
  .dimension-indicator-settings-page {
    display: flex;
    .left {
      width: 46%;
      margin-right: 41px;
      .search {
        margin-bottom: 18px;
        .el-button {
          color: #fff;
          background-color: #4e6df6;
          border-color: #4e6df6;
        }
      }
      .configuration-con {
        padding: 18px 20px;
        background: #f3f3f3;
        border-radius: 4px;
        height: calc(100% - 50px);
        .configuration-group {
          .configuration-group-name {
            margin-bottom: 18px;
            font-size: 14px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #333333;
            i {
              margin-left: 24px;
              cursor: pointer;
            }
          }
        }
      }
    }
    .configuration-group-checked {
      display: flex;
      flex-wrap: wrap;
      width: 100%;
      .el-row {
        width: 100%;
      }
      .el-checkbox {
        margin-bottom: 14px;
      }
    }
    .right {
      flex: 1;
      padding-top: 74px;
      .right-header {
        text-align: center;
      }
      .right-select {
        text-align: center;
        padding: 10px 0px;
        border-bottom: 1px solid #e1e1e1;
        line-height: 30px;
      }
      .el-icon-rank {
        cursor: move;
      }
    }
  }
}
.setting-title {
  font-weight: 600;
  font-size: 14px;
  color: #333333;
  padding-bottom: 10px;
  box-sizing: border-box;
  border-bottom: 1px solid #eeeeee;
}
.bottom-btn {
  text-align: center;
  font-size: 14px;
  color: #006aff;
  border-top: 1px solid #eeeeee;
  padding-top: 10px;
  box-sizing: border-box;
  cursor: pointer;
}
</style>
